package com.ztman.router.common.presenter.base;

import com.ztman.router.common.base.BaseView;
import com.ztman.router.common.core.DataManager;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

/**
 * @Title:BasePresenter
 * @Package:com.ztman.router.common.presenter
 * @Description:
 * @Auther:YJH
 * @Email:yuannunhua@gmail.com
 * @Date:2018/5/1117:26
 */
public class BasePresenter<T extends BaseView> implements AbstractPresenter<T> {

    protected T mView;
    private DataManager mDataManager;
    private CompositeDisposable compositeDisposable;

    public BasePresenter(DataManager _dataManager) {
        this.mDataManager = _dataManager;
    }

    protected void addSubscribe(Disposable disposable) {
        if (compositeDisposable == null) {
            compositeDisposable = new CompositeDisposable();
        }
        compositeDisposable.add(disposable);
    }

    @Override
    public void attachView(T view) {
        this.mView = view;
    }

    @Override
    public void detachView() {
        this.mView = null;
        if (compositeDisposable != null) {
            compositeDisposable.clear();
        }
    }

    @Override
    public void setLoginStatus(boolean loginStatus) {
        mDataManager.setLoginStatus(loginStatus);
    }

    @Override
    public boolean getLoginStatus() {
        return mDataManager.getLoginStatus();
    }

    @Override
    public String getLoginAccount() {
        return mDataManager.getLoginAccount();
    }

    @Override
    public void setLoginAccount(String loginAccount) {
        mDataManager.setLoginAccount(loginAccount);
    }


}
